package com.jyb.model;

import com.jfinal.plugin.activerecord.Model;
import com.jyb.util.MD5Util;
import com.jyb.util.StringUtils;
import com.jyb.vo.UserVo;

public class User extends Model<User>{

	private static final long serialVersionUID = -2929579257546666751L;
	public static final User dao = new User();

	public static UserVo getUserVo(User user){
		UserVo userVo=new UserVo();
		if(user!=null){
			userVo.setCellphone(user.getStr("cellphone"));
			userVo.setCreateTime(user.getDate("createTime"));
			userVo.setEmail(user.getStr("email"));
			userVo.setId(user.getStr("id"));
			userVo.setNickname(user.getStr("nickname"));
			userVo.setPassword(user.getStr("password"));
		}
		return userVo;
	}
	
	public User getUserByCellphoneAndPassword(String cellphone,String password){
		if(StringUtils.isEmpty(cellphone)){
			return null;
		}
		if(StringUtils.isEmpty(password)){
			return null;
		}
		password=MD5Util.MD5(password);
		
		return this.findFirst("select * from t_user t where t.cellphone=? and password=?",cellphone,password);
	}
	
	public User getUserByCellphone(String cellphone){
		return this.findFirst("select * from t_user t where t.cellphone=?",cellphone);
	}
}
